﻿// ResPkgEdit.cpp: 实现文件
//

#include "pch.h"
#include "ResPkg.h"
#include "ResPkgEdit.h"
#include "afxdialogex.h"


// CResPkgEdit 对话框

IMPLEMENT_DYNAMIC(CResPkgEdit, CDialogEx)

CResPkgEdit::CResPkgEdit(int nLevel, CString strSubName, CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_EDIT, pParent)
{
	m_nLevel = nLevel;
	m_strSubName = strSubName;
	m_strOldSubName = strSubName;
}

CResPkgEdit::~CResPkgEdit()
{
}

void CResPkgEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_LEVEL, m_comboLevel);
	DDX_Control(pDX, IDC_EDIT_NAME, m_editSubName);
}


BEGIN_MESSAGE_MAP(CResPkgEdit, CDialogEx)
	ON_BN_CLICKED(IDOK, &CResPkgEdit::OnBnClickedOk)
END_MESSAGE_MAP()


// CResPkgEdit 消息处理程序


BOOL CResPkgEdit::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	m_comboLevel.SetCurSel(m_nLevel - 1);
	m_editSubName.SetWindowText(m_strSubName);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CResPkgEdit::OnBnClickedOk()
{
	m_editSubName.GetWindowText(m_strSubName);
	if (m_strSubName != _T(""))
	{
		if (m_editSubName.GetWindowTextLength() * sizeof(TCHAR) > MAX_SUBNAME_LEN)
		{
			CString strErr;
			ASSERT(strErr.LoadString(IDS_SUBNAME_LIMIT));
			MessageBox(strErr);
		}
		else
		{
			m_nLevel = m_comboLevel.GetCurSel() + 1;
			CDialogEx::OnOK();
		}
	}
	else
	{
		CString strWarn;
		ASSERT(strWarn.LoadString(IDS_EMPTY_NAME));
		MessageBox(strWarn);
	}
}
